home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Multipane Dialogs Code / LDEF / LDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-17  |  2.9 KB  |  98 lines  |  [TEXT/MMCC]

  1. // File "Icon LDEF.c" - Icon Suite LDEF Routine  10/16/93
  2. //   Code is shamelessly based on Apple Snippet by Steven Falkenburg 5/23/91
  3. //   This code is placed in the public domain for free use and distribution! MJS
  4. //   Slight modifications by Norman Franke
  5.  
  6. #include <GestaltEqu.h>
  7. #include "Icons.h"
  8.  
  9. // * **************************************************************************** * //
  10. // * **************************************************************************** * //
  11.  
  12. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  13.         short dataOffset, short dataLen, ListHandle theList)
  14. {
  15.     long response;
  16.     Point drawPt;
  17.     Rect iconRect, textRect;
  18.     Ptr cellData;
  19.     Handle iconHdl;
  20.     ListPtr theListPtr;
  21.     SignedByte hStateList, hStateCells;
  22.     FontInfo fontInfo;
  23.     short textSize, textFont;
  24.     
  25.     if (Gestalt(gestaltSystemVersion, &response) || (response < 0x0700)) return;
  26.     textSize = (*theList)->port->txSize, textFont = (*theList)->port->txFont;
  27.     
  28.     TextFont(geneva);
  29.     TextSize(9);
  30.     
  31.     // Lock down the handles
  32.     hStateList = HGetState((Handle) theList);
  33.     HLock((Handle) theList);
  34.     theListPtr = *theList;
  35.     hStateCells = HGetState((Handle) theListPtr->cells);
  36.     HLock((Handle) theListPtr->cells);
  37.     cellData = *(theListPtr->cells);
  38.     
  39.     GetFontInfo(&fontInfo);
  40.     SetRect(&iconRect, cellRect->left + (theListPtr->cellSize.h >> 1) - 16,
  41.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) - 16,
  42.             cellRect->left + (theListPtr->cellSize.h >> 1) + 16,
  43.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) + 16);
  44.     SetPt(&drawPt, (iconRect.left + iconRect.right) >> 1, 
  45.             iconRect.bottom + fontInfo.ascent + 2);
  46.  
  47.     switch (message) {
  48.         case lInitMsg:
  49.               break;
  50.  
  51.         case lDrawMsg:
  52.             EraseRect(cellRect);
  53.         case lHiliteMsg:
  54.             
  55.               if (dataLen > 0) {
  56.                   if (dataLen >= 4) {
  57.                       BlockMove(cellData + dataOffset, &iconHdl, 4);
  58.                       if (iconHdl) PlotIconSuite(&iconRect, 0, (hilited) ? ttSelected : 0, iconHdl);
  59.                       else if (hilited) PaintRect(&iconRect);
  60.                       else EraseRect(&iconRect);
  61.                       dataLen -= 4;
  62.                       dataOffset += 4;
  63.                   }
  64.                 
  65.                 // Condense if the text doesnt fit
  66.                 if (TextWidth(cellData, dataOffset, dataLen) >
  67.                         (cellRect->right - cellRect->left)) TextFace(condense);
  68.         
  69.                 SetRect(&textRect, drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1) - 2,
  70.                         drawPt.v - fontInfo.ascent - 1,
  71.                         drawPt.h + (TextWidth(cellData, dataOffset, dataLen) >> 1) + 2,
  72.                         drawPt.v + 2);
  73.  
  74.                 EraseRect(&textRect);
  75.                   MoveTo(drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1), drawPt.v);
  76.                 DrawText(cellData, dataOffset, dataLen);
  77.  
  78.                 if (hilited) {
  79.                     LMSetHiliteMode(LMGetHiliteMode() ^ (1 << hiliteBit));
  80. //                      (* (char *) &HiliteMode) ^= (1 << hiliteBit);
  81.                       InvertRect(&textRect);
  82.                   }
  83.               }
  84.         
  85.               break;
  86.  
  87.         case lCloseMsg:
  88.               break;
  89.     }
  90.     
  91.     // Restore the Handles
  92.     HSetState((Handle) theListPtr->cells, hStateCells);
  93.     HSetState((Handle) theList, hStateList);
  94.     
  95.     TextFont(textFont);
  96.     TextSize(textSize);
  97. }
  98.